package com.bookmanage.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bookmanage.dao.RentAddConn;

@WebServlet("/RentBookServlet")
public class RentBookServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public RentBookServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置数据编码，防止插入到mysql乱码
        request.setCharacterEncoding("utf-8");
        //获取到要添加书籍的信息
        String name = request.getParameter("name");
        String book = request.getParameter("book");
        String grade = request.getParameter("grade");
        String sex = request.getParameter("sex");
        String start = request.getParameter("start");
        String end = request.getParameter("end");

        RentAddConn.add(name, sex, grade, book, start, end);

        //解决中文乱码
        response.setContentType("text/html; charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print("<script>alert('用户新增成功')</script>");
    }

}
